﻿using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using VIT.DataHelper.DataAccess;

namespace VIT.Business
{
    public class Category : Category_Base
    {
        SQLSupport sqlSupport = new SQLSupport();

        #region Constructor
        public Category(string Id = "",
                        string ParentId = "",
                        string LanguageId = "",
                        string Image = "",
                        string Title = "",
                        string Description = "")
        {
            this.Id = Id;
            this.ParentId = ParentId;
            this.LanguageId = LanguageId;
            this.Image = Image;
            this.Title = Title;
            this.Description = Description;
        }
        #endregion

        #region FrontEnd
        public DataTable GetList(string categoryIds)
        {
            string strQuery = "select Id, ParentId, Image, Title, Description from Category, Category_Language where Id=CategoryId and ParentId in ("
                            + categoryIds +") and LanguageId=@LanguageId and Published=1 Order by Orders";
            SqlParameter LanguageId = new SqlParameter("@LanguageId", this.LanguageId);
            return sqlSupport.ExecuteDataset(false, strQuery, LanguageId).Tables[0];
        }

        public void getOne()
        {
            string strQuery = "select ParentId, Title, Image, Description from Category, Category_Language where Id=CategoryId and LanguageID=@LanguageId and Id=@Id and Published=1";
            SqlParameter Id = new SqlParameter("@Id", this.Id);
            SqlParameter LanguageId = new SqlParameter("@LanguageId", this.LanguageId);
            DataTable dt = sqlSupport.ExecuteDataset(false, strQuery, Id, LanguageId).Tables[0];

            if (dt.Rows.Count > 0)
            {
                this.Image = dt.Rows[0]["Image"].ToString();                
                this.Title = dt.Rows[0]["Title"].ToString();
                this.Description = dt.Rows[0]["Description"].ToString();
                this.ParentId = dt.Rows[0]["ParentId"].ToString();
            }
            else this.Id = "";
        }
        #endregion
    }
}
